<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\web\Session;

?>
<include file="./App/Tpl/Admin/header.html" />
    <include file="./App/Tpl/Admin/left.html" />
     <div class="pull-left diywap_right">    
        <div class="panel panel-info">        
            <div class="panel-heading">添加新闻</div>        
                <div class="panel-body">            
                    <div class="row">                
                        <div class="col-md-12">                    
                            <div class="panel panel-default">                        
                                <!-- Default panel contents -->                       
                                 <div class="panel-heading">                            
                                 添加项                        
                                 </div>                       
                                  <!-- List group -->  
                                  <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']])?>                      
                                  <table class="table table-bordered table-hover">                              <tr class="active">                                
                                            <td>标题:</td>
                                            <td>
                                                <?= $form->field($model,'title')->textInput(['style'=>'width:300px;'])->label(false)?>
                                            </td>
                                        </tr>                            
                                        <tr class="warning">                                
                                            <td>摘要:</td>                                
                                            <td>
                                                
                                                <?= $form->field($model,'digest')->textarea(['style'=>"width:300px;height:100px;"])->label(false)?>
                                            </td>                           
                                        </tr>                            
                                        <tr class="success">                                
                                            <td>内容:</td>                                
                                            <td height="500px">                                    
                    
                                                 <!--<textarea name="<?php echo $model->content;?>" id='editor' style="width:800px;height:300px;"></textarea>-->
                                                   
                                                 <?= $form->field($model,'content')->textarea(['id'=>'editor','class'=>'textarea'])->label(false)?>
                                            </td>                            
                                        </tr>                            
                                        <tr class="warning">                                
                                            <td>图片:</td>                                
                                            <td>
                                                <?= $form->field($model,'photo')->fileInput(['name'=>'Addnews'])->label(false)?>
                                                <div id ="div1"></div>
                                                <!--<input type="button" value="删除" onclick="delImage()"/>-->
                                            </td>
                                                                      
                                        </tr>                            
                                         <tr class="warning">                                
                                            <td colspan="2" align="center"><input type="submit" value="提交"></td>                                
                                                                        
                                        </tr>                            
                                    </table> 
                                    <?php ActiveForm::end();?>                   
                                  </div>                
                                </div>            
                            </div>       
                        </div>    
                    </div>
                </div>
<?php
    if(Yii::$app->session->hasFlash('info')):
?>
<script>
    alert('<?php echo Yii::$app->session->getFlash("info")?>');
</script>
<?php endif?>

<script type="text/javascript">
	$(document).ready(function(){
		$(document).on('change','#addnews-photo',function(){
			$('#w0').ajaxSubmit({
				url:'upload.php',
				//type:'post',
				dataType:'json',
				success:function(data){
					var str='<img src="'+data+'"/>';
					
					$('#div1').append(str);
				}
			})
		})
	})

</script>